package com.pagepub.core.tag.validator;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class ValidateUsername extends FormValidateBasic {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2203912740689340847L;
	private String callfuntionaname;
	private String functionname;
	private String rightimage;
	private String submitvalidate;	
	private String rightwordcolor;
	public String getRightwordcolor() {
		return rightwordcolor;
	}
	public void setRightwordcolor(String rightwordcolor) {
		this.rightwordcolor = rightwordcolor;
	}
	public String getRightimage() {
		return rightimage;
	}
	public void setRightimage(String rightimage) {
		this.rightimage = rightimage;
	}
	public String getFunctionname() {
		return functionname;
	}
	public void setFunctionname(String functionname) {
		this.functionname = functionname;
	}
	public String getCallfuntionaname() {
		return callfuntionaname;
	}
	public void setCallfuntionaname(String callfuntionaname) {
		this.callfuntionaname = callfuntionaname;
	}		
	
	public int doStartTag() throws JspException {  		
         JspWriter out=this.pageContext.getOut();
         StringBuffer str=new StringBuffer();
		ValidateEmpty validateempty = new ValidateEmpty();
        validateempty.setWordcolor(wordcolor);
        validateempty.setWrongimage(wrongimage);
		NouserChinese nochinese = new NouserChinese();
        nochinese.setWordcolor(wordcolor);
        nochinese.setWrongimage(wrongimage);
		ValidateLength validateLength = new ValidateLength();
		validateLength.setWordcolor(wordcolor);
		validateLength.setWrongimage(wrongimage);
		IsExit isexit=new IsExit();
		isexit.setCallfuntionaname(callfuntionaname);
		this.setFunctionname("validateusernameexit");
		isexit.setFunctionname(functionname);
		isexit.setSubmitvalidate(submitvalidate);
		isexit.setRightimage(rightimage);
        isexit.setWordcolor(wordcolor);
        isexit.setWrongimage(wrongimage);
        isexit.setRightwordcolor(rightwordcolor);
		// TODO 自动生成方法存根
		str.append(validateempty.validateempty());
		str.append(nochinese.nouserchinese());
		str.append(validateLength.validatelength());
		str.append(isexit.isexit());
		str.append(validateusername());
		try {
			
			out.print(str);
//			System.out.println(str);
		} catch (IOException e) {
			// TODO 自动生成 catch 块

			e.printStackTrace();
		}
		return 1;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自动生成方法存根

	}

	public StringBuffer validateusername(){
		StringBuffer str=new StringBuffer();
//		 String emptyelement="";
	      String pluselement="";
	      if(this.submitvalidate.equalsIgnoreCase("true")){
//				emptyelement="emptyelement(realname);";
				pluselement="else pluselement(realname);";
			}
		str.append("<script language=\"javascript\">");
//		realvalue当前验证值  spanname 显示span 的id   realname显示的名称  nextelmentname 下一个要验证的元素  
		str.append("function validateusername(realvalue,minlenth,maxlenth,spanname,realname,callfunvalue,iscorp) {");
		//str.append("alert(spanname);");
		str.append("if(Validateempty(realvalue,realname,spanname))");
		str.append("if(Nouserchinese(realvalue,realname,spanname))");
		str.append(	" if(ValidateLength(realvalue,minlenth,maxlenth,realname,spanname))");
		str.append(		"validateusernameexit(realvalue,spanname,realname,callfunvalue,iscorp);");
		str.append(pluselement);
		str.append(pluselement);
		str.append(pluselement);
		str.append("}");
		str.append("</script>");
		return str; 
	}
	public String getSubmitvalidate() {
		return submitvalidate;
	}
	public void setSubmitvalidate(String submitvalidate) {
		this.submitvalidate = submitvalidate;
	}
}
